<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<title>国家城市</title>
	<meta name="description" content="Kenny is a Dashboard & Admin Site Responsive Template by hencework." />
	<meta name="keywords" content="admin, admin dashboard, admin template, cms, crm, Kenny Admin, kennyadmin, premium admin templates, responsive admin, sass, panel, software, ui, visualization, web app, application,sortable, reorder, list, javascript, html5, drag and drop, dnd, animation, groups, angular, ng-sortable, effects, rubaxa" />
	<meta name="author" content="hencework" />
	<!-- Favicon -->
	<link rel="shortcut icon" href="/favicon.ico">
	<link rel="icon" href="/favicon.ico" type="image/x-icon">

	<!-- Data table CSS -->
	<link href="__STATIC__/admin/dist/datatables/media/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
	<!-- Custom CSS -->
	<link href="__STATIC__/admin/dist/css/style.css" rel="stylesheet" type="text/css">
	<link href="__STATIC__/admin/dist/css/jquery-ui.css" rel="stylesheet" type="text/css">
	<link href="__STATIC__/admin/dist/css/app.css" rel="stylesheet" type="text/css">
	<!--
	<link href="dist/css/dataTables.fixedColumns.css" rel="stylesheet" type="text/css"> -->
	<link href="__STATIC__/admin/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

	<style>
		.page-continer{
			position: absolute;
		   left: 0;
		   right: 0;
		   bottom: 0;
		   top: -50px;
		   -webkit-overflow-scrolling: touch;
		   overflow-y: scroll
		}
	</style>
</head>

<body>
	<div class="wrapper">
		<!-- Main Content -->
		<div class="page-wrapper page-continer">


			<div class="container-fluid">
				<!-- Row -->
				<div class="row">
					<div class="col-sm-12">
						<div class="panel panel-default card-view">
							<div class="panel-heading">
								<div class="pull-left pis">
									<div class="search-content">
										<form method="POST" id="form" action="/admin/area/searchArea">
											<div class="row form-txt">
												<?php
													$parent = session("parent");
												?>
												<input type="hidden" id="first-parent" value='<?php echo $parent;?>'>
												<div class="col-sm-3 col-xs-12">
													<div class="form-group">
														<label class="control-label col-xs-3 lables mt-10">編號： </label>
														<div class="col-xs-9"><input type="text" id="search-id" name="sid" class="ft-1 form-control" value='<?php echo isset(session("$parent")["sid"])?session("$parent")["sid"]:"";?>'/></div>
													</div>
												</div>

												<div class="col-sm-4 col-xs-12">
													<div class="form-group">
														<label class="control-label col-xs-3 lables mt-10">中文名稱：</label>
														<div class="col-xs-9"><input type="text" id="search-name" name="name" class="ft-1 form-control" value='<?php echo isset(session("$parent")["name"])?session("$parent")["name"]:"";?>'/></div>
													</div>
												</div>

												<div class="col-sm-4 col-xs-12">
													<div class="form-group">
														<label class="control-label col-xs-3 lables mt-10">英文名稱： </label>
														<div class="col-xs-9"><input type="text" id="search-en-name" name="en_name" class="ft-1 form-control" value='<?php echo isset(session("$parent")["en_name"])?session("$parent")["en_name"]:"";?>'/></div>
													</div>
												</div>
												<div class="col-sm-1 col-xs-12 mt-1">
													<div class="form-group">
														<div class="col-xs-2 mt-5" style="    text-align: right;"><input type="submit" name="btn" id="sub-btn" value="查詢"></div>
													</div>
												</div>
											</div>
										</form>
									</div>
									<div class="search-btn"><i class="fa fa-angle-double-up icon-01"></i><i class="fa fa-angle-double-down icon-02"></i></div>
								</div>
								<div class="clearfix"></div>
							</div>
							<div class="Editors">
								<div class="dataTables_length" id="edit_datable_2_length" style="margin-bottom:0;">
									<a href="javascript:void(0)" id="area-insert">
										<input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="新增" id="btnAdd"
										 class="SrvButton"></a>
									<input type="button" name="btnAdd" value="删除" id="Deletes" class="SrvButton" style="text-align:center;">
									<span>
										<a href="javascript:;">
											<input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="清空筛选条件" id="btnReset"  class="SrvButton">
										</a>
									</span>
									<input type="button" class="SrvButton" value="刷新" onclick="getReload()">
									<input type="button" id="modal_sz" class="SrvButton" value="设置" onclick="">
									<?php if(session('user')['roleid'] == '1'){ ?>
										<span><a href="/admin/cache/cacheAll?type=area" target="_blank"><input type="button" class="SrvButton" value="重新生成缓存"></a></span>
									<?php } ?>
									<label>显示
										<?php
											if(session('area_count')){
												$count=session('area_count');
											}else{
												$count=10;
											}
										?>
										<select name="count" aria-controls="edit_datable_2" id="count">
										<option value="10"<?php if($count==10) {echo 'selected="selected"';} ?>>10</option>
										<option value="20"<?php if($count==20) {echo 'selected="selected"';} ?>>20</option>
										<option value="30"<?php if($count==30) {echo 'selected="selected"';} ?>>30</option>
										<option value="40"<?php if($count==40) {echo 'selected="selected"';} ?>>40</option>
										<option value="50"<?php if($count==50) {echo 'selected="selected"';} ?>>50</option>
										</select> 项结果
									</label>
									<div class='page'>{$page}</div>
								</div>
							</div>
							<div class="panel-wrapper collapse in">
								<div class="panel-body">
									<div class="table-wrap">
										<div class="table-responsive">
											<div class="hidden_moduel disnonde">
												<form>
													<input type="hidden" class="url" value="{$url}">
													<div class="move_td">
														<ul id="foo" class="block__list block__list_tags" onclick="sorTable()">
															<?php if(empty($order)){ ?>
																<li class="order" name="bh" hideCol="1" onclick="hideCol(this)">編號</li>
																<li class="order" name="mc" hideCol="1" onclick="hideCol(this)">名稱</li>
																<li class="order" name="ywmc" hideCol="1" onclick="hideCol(this)">英文名稱</li>
																<li class="order" name="pxh" hideCol="1" onclick="hideCol(this)">排序号</li>
																<li class="order" name="gj" hideCol="1" onclick="hideCol(this)">国家</li>
																<li class="order" name="sd" hideCol="1" onclick="hideCol(this)">鎖定</li>
																<li class="order" name="xs" hideCol="1" onclick="hideCol(this)">显示</li>
																<li class="order" name="py" hideCol="1" onclick="hideCol(this)">拼音</li>
																<li class="order" name="pyjx" hideCol="1" onclick="hideCol(this)">拼音简写</li>
																<li class="order" name="bzsm" hideCol="1" onclick="hideCol(this)">備註說明</li>
															<?php }else{
															    foreach($order as $k=>$v){
															?>
																<li class="order" name="{$k}" hideCol="{$v[1]}" onclick="hideCol(this)" {if condition="empty($v[1])"}style="background-color: rgb(204, 204, 204);" draggable="false"{/if}>{$v[0]}</li>
															<?php } }?>
														</ul>
													</div>
													<div class="move_btn">
														<input class="btn btn-danger" type="button" value="取消" onclick="window.location = window.location.href">
														<input class="btn btn-success" type="button" value="保存" onclick="submitBtnClick()">
													</div>
												</form>
											</div>
											<div id="table_wappers" class="dataTables_wrapper no-footer">
												<table id="datable_1" class="table table-hover display" style="width: 1800px;">
													<thead>
														<tr>
															<th style="width:30px;" name="checkme"><input type="checkbox"></th>
															<th name="xg" style="width:50px;">修改</th>
															<th name="sc" style="width:50px;">刪除</th>
															<th name="checkme" style="width:100px;">操作</th>
															{if empty($order)}
															<th name="hh" style="width:50px;">行號</th>
															<th name="bh" style="width:50px;">編號</th>
															<th name="mc" style="width:180px;" data-name="a.name " data-asc="desc">名稱</th>
															<th name="ywmc" style="width:180px;" data-name="p.en_name " data-asc="desc">英文名稱</th>
															<th name="pxh" style="width:80px;" data-name="a.sort " data-asc="desc">排序号</th>
															<th name="gj" style="width:50px;" data-name="a.is_country " data-asc="desc">国家</th>
															<th name="sd" style="width:50px;" data-name="a.is_lock " data-asc="desc">鎖定</th>
															<th name="xs" style="width:50px;" data-name="a.is_hidden " data-asc="desc">显示</th>
															<th name="py" style="width:180px;" data-name="a.pinyin " data-asc="desc">拼音 </th>
															<th name="pyjx" style="width:180px;" data-name="a.spinyin " data-asc="desc">拼音简写</th>
															<th name="bzsm" data-name="a.remark " data-asc="desc" style="width: 300px">備註說明</th>
															{else}
																<?php
																	foreach ($order as $k => $v) {
																		switch($k){
																			case 'bh':
																			    $reorder = '';
																			    break;
																			case 'mc':
																			    $reorder = 'data-name="a.name " data-asc="desc"';
																			    break;
																			case 'ywmc':
																			    $reorder = 'data-name="p.en_name " data-asc="desc"';
																			    break;
																			case 'pxh':
																			    $reorder = 'data-name="a.sort " data-asc="desc"';
																			    break;
																			case 'gj':
																			    $reorder = 'data-name="a.is_country " data-asc="desc"';
																			    break;
																			case 'sd':
																			    $reorder = 'data-name="a.is_lock " data-asc="desc"';
																			    break;
																			case 'xs':
																			    $reorder = 'data-name="a.is_hidden " data-asc="desc"';
																			    break;
																			case 'py':
																			    $reorder = 'data-name="a.pinyin " data-asc="desc"';
																			    break;
																			case 'pyjx':
																			    $reorder = 'data-name="a.spinyin " data-asc="desc"';
																			    break;
																			case 'bzsm':
																			    $reorder = 'data-name="a.remark " data-asc="desc" style="width: 300px"';
																			    break;
																			default:
															  		  			$reorder = '';
																		}
																	?>
																		<th name="{$k}" {$reorder} data="{$v[1]=='0' ? 'hide' :'';}";>{$v[0]}</th>
																<?php
																	}
																?>
															{/if}
														</tr>
										                {if (is_numeric($area))}
										                	{if $area==0}
										                	<tr><td colspan="15" id="no-area" style="color:red;border-bottom: none;">暂无相关的记录显示</td></tr>
										                	{else}
										                	<tr><td id="data-tr" colspan="15" style="color:red;border-bottom: none;">暂无相关的记录显示<br/><a href="javascript:void(0)" style="margin-left:10px" onclick="getUp(this)" data-id="{$area}"><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一级" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px;margin-left:-10px;border-bottom: none;"></a></td></tr>;
										                	{/if}
										                {/if}

													</thead>

													<tbody class="list">
														<?php if(!is_numeric($area)){ ?>
														<?php
															foreach($area as $k=>$v){
																if($v['is_lock'] == 1){ // 是否锁定
																	$is_lock = '<span style="color: red">N</span>';
																}else{
																	$is_lock = 'Y';
																}
																if($v['is_hidden'] == 1){ // 是否显示
																	$is_hidden = 'Y';
																}else{
																	$is_hidden = '<span style="color: red">N</span>';
																}
																if($v['is_country'] == 1){ // 是否显示
																	$is_country = 'Y';
																}else{
																	$is_country = '<span style="color: red">N</span>';
																}
														?>
														<tr>
															<td><input type="checkbox" name="ids[]" onclick="getData()" value="{$v.id}" ></td>
															<td name="xg" class="jsgrid-cell jsgrid-control-field jsgrid-align-center" style="text-align: center;">
																<a href="/admin/area/areaShow?id={$v.id}" class="text-inverse  p-r-10" title="" data-toggle="tooltip" data-original-title="Edit"><i
																	 class="fa fa-pencil"></i></a>
															</td>
															<td name="sc">
																<a href="/admin/area/isDeleteArea?id={$v.id}" class="text-inverse" title="" data-toggle="tooltip" data-original-title="Delete"><i
																	 class="fa fa fa-trash"></i></a>
															</td>
															<td name="checkme" class="area-parent" data-id="{$v.parent}">
																	<a href="javascript:void(0)" onclick="getNext(this)" data-id="{$v.data_id}">
																		<input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="管理下一级" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;">
																	</a>
																	<br/>
																	{if($v.parent!=0)}
																	<a href="javascript:void(0)" onclick="getUp(this)" data-id="{$v.parent}"><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一級" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px"></a>
																	{/if}
																</td>
															{if condition="empty($order)"}
																<td name="hh">{$k+1}</td>
																<td name="bh">{$v.data_id}</td>
																<td name="mc">{$v.name}</td>
																<td name="ywmc">{$v.en_name}</td>

																<td name="pxh">{$v.sort}</td>
																<td name="gj">{$is_country}</td>
																<td name="sd">{$is_lock}</td>
																<td name="xs">{$is_hidden}</td>
																<td name="py">{$v.pinyin}</td>
																<td name="pyjx">{$v.spinyin}</td>
																<td name="bzsm"><div style="max-height:30px;width:100%;overflow: hidden;text-overflow: ellipsis;font-size:12px">{$v.remark}</div></td>
															{else}
																<?php foreach($order as $key=>$value){
																	if($key == 'sd'){
																		switch($v[$translate[$key]]){
																			case '1':
																				$is_lock = '<span style="color: red">N</span>';
																			break;
																			case '2':
																				$is_lock = 'Y';
																			break;
																		}
																?>
																<td name='sd' data="{$value[1]=='0' ? 'hide' :'';}";>{$is_lock}</td>
																<?php
																	}elseif($key == 'xs'){
																		switch($v[$translate[$key]]){
																			case '1':
																				$is_hidden = 'Y';
																			break;
																			case '2':
																				$is_hidden = '<span style="color: red">N</span>';
																			break;
																		}
																?>
																<td name='xs' data="{$value[1]=='0' ? 'hide' :'';}";>{$is_hidden}</td>
																<?php
																	}elseif($key == 'gj'){
																		switch($v[$translate[$key]]){
																			case '1':
																				$is_country = 'Y';
																			break;
																			case '2':
																				$is_country = '<span style="color: red">N</span>';
																			break;
																		}
																?>
																<td name='gj' data="{$value[1]=='0' ? 'hide' :'';}";>{$is_country}</td>
																<?php
																	}elseif($key == 'bzsm'){
																?>
																<td name='bzsm' data="{$value[1]=='0' ? 'hide' :'';}";><div style="max-height:30px;width:100%;overflow: hidden;text-overflow: ellipsis;font-size:12px">{$v[$translate[$key]]}</div></td>
																<?php
																	}else{
																?>
																<td name="{$key}" data="{$value[1]=='0' ? 'hide' :'';}";>{$key=='hh' ? $k+1 : $v[$translate[$key]]}</td>
																<?php
																	}
																}
																?>


															{/if}
														</tr>
														<?php }?>
														<?php } ?>
													</tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- /Row -->
		</div>
	</div>
	<!-- /Main Content -->
	<!-- /#wrapper -->
	<!-- JavaScript -->
	<!-- jQuery -->
	<script src="__STATIC__/admin/dist/js/jquery.min.js"></script>

	<!-- Bootstrap Core JavaScript -->
	<script src="__STATIC__/admin/dist/js/bootstrap.min.js"></script>
	<script src="__STATIC__/admin/dist/js/dataTab.js"></script>
	<!-- <script src="dist/js/dataTables.fixedColumns.js"></script> -->
	<script src="__STATIC__/admin/dist/js/jquery-ui.min.js"></script>
	<!-- Data table JavaScript -->
	<script src="__STATIC__/admin/dist/datatables/media/js/jquery.dataTables.min.js"></script>
	<script src="__STATIC__/admin/dist/js/dataTables-data.js"></script>
	<!-- Slimscroll JavaScript -->
	<script src="__STATIC__/admin/dist/js/jquery.slimscroll.js"></script>
	<!-- Fancy Dropdown JS -->
	<script src="__STATIC__/admin/dist/js/dropdown-bootstrap-extended.js"></script>
	<!-- Init JavaScript -->
	<script src="__STATIC__/admin/dist/js/init.js"></script>
	<script src="__STATIC__/admin/dist/js/jquery-ui.js"></script>
	<!-- sort JavaScript -->
	<script src="__STATIC__/admin/dist/js/angular.min.js"></script>
	<script src="__STATIC__/admin/dist/js/Sortable.js"></script>
	<script src="__STATIC__/admin/dist/js/ng-sortable.js"></script>
	<script src="__STATIC__/admin/dist/js/data-table.js"></script>


</body>

</html>
<script type="text/javascript">
$(function(){
	history.replaceState(null, "", "/admin/area/area");
	$("input[type='checkbox']").click(function(){
	    var trlength = $(".list tr").length;
	    var checklength = $(".list input[type='checkbox']:checked").length;
	    if(trlength == checklength){
	        $('[name="checkme"] > input').first().prop("checked",true);
	    }else{
	        $('[name="checkme"] > input').first().prop("checked",false);
	    }
	})
	$(".odd").children(".dataTables_empty").remove();
	var parent = $("#first-parent").val();
	if($(".area-parent").attr("data-id")) {

	} else {
		$('.list').append('<input type="hidden" class="area-parent" data-id="'+parent+'">');
	}

	var sort = "<?php echo session('area_sort');?>";
	if(sort) {
		var asc = sort.split(" ");
		if(asc[1]=="desc") {
			$('[data-name="'+asc[0]+' "]').attr('data-asc','asc');
			$('[data-name="'+asc[0]+' "]').attr('class','sorting_disabled sorting sorting_asc sorting_desc');
		} else {
			$('[data-name="'+asc[0]+' "]').attr('data-asc','desc');
			$('[data-name="'+asc[0]+' "]').attr('class','sorting_disabled sorting sorting_asc');
		}

	}
})
//清空筛选条件
$('#btnReset').click(function(){
    $.ajax({
        url:"{:url('admin/hotel/searchReset')}",
        data:{'type':'clear','country':0},
        type:'post',
        success:function(res){
            if(res==1){
                window.location.reload();
                return false;
            }
        }
    });
});

//点击下一级
function getNext(_this){
	var $_this = $(_this);
	var id = $_this.attr('data-id');
	var count = $("#count").val();
	var sid = $("#search-id").val();
	var sname = $("#search-name").val();
	var en_name = $("#search-en-name").val();
	$.ajax({
		type: "POST",
		url : '/admin/area/getSonData',
		data: {'id':id,'count':count,'sid':sid,'sname':sname,'en_name':en_name},
		success:function(data){
			$("#search-id").val("");
			$("#search-name").val("");
			$("#search-en-name").val("");
			if(data.session) {
				$("#search-id").val(data.session.sid);
				$("#search-name").val(data.session.name);
				$("#search-en-name").val(data.session.en_name);
			}
			if(isNaN(data.area)) {
				getdataSon(data); // 调用html渲染方法
			} else {
				var len = 15;
				tr = '<tr class="area-parent" data-id="'+data.area+'"><td colspan="15" style="color:red">暂无相关的记录显示<br/><a href="javascript:void(0)" style="margin-left:10px" onclick="getUp(this)" data-id='+data.area+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一级" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px;margin-left:-10px"></a></td></tr>';
				$('.list').html(tr);
				$('.page').hide();
			}
		}
	})
}

//返回上一级
function getUp(_this){
	var $_this = $(_this);
	var id = $_this.attr('data-id');
	var count = $("#count").val();
	$.ajax({
		type: "POST",
		url : '/admin/area/getParentData',
		data: {'id':id,'count':count},
		success:function(data){
			if(data.session) {
				$("#search-id").val(data.session.sid);
				$("#search-name").val(data.session.name);
				$("#search-en-name").val(data.session.en_name);
			} else {
				$("#search-id").val('');
				$("#search-name").val('');
				$("#search-en-name").val('');
			}
			$("#data-tr").parent().remove();
			delete data.session;
			$('.page').show();
			if(data.area[0].parent==0) {
				page(data);
			}else{
				getdataSon(data);
			}
		}
	})
}

//点击显示多少条
$(function(){
	//变动事件
	$('#count').change(function(e) {
		e.preventDefault();
		if($(".sorting_asc").attr("data-name")) {
			var sort = $(".sorting_asc").attr("data-name");
		} else {
			var sort = "";
		}

		if($(".sorting_asc").attr("data-asc")) {
			var data = $(".sorting_asc").attr("data-asc");
			if(data == "asc") {
				var asc = "desc";
			} else {
				var asc = "asc";
			}
		} else {
			var asc = "";
		}
		var parent = $(".area-parent").attr("data-id");
		var count = $("#count").serialize()+'&'+$("#form").serialize()+'&parent='+parent+'&sort='+sort+'&asc='+asc;
		$.ajax({
			url : "/admin/area/area",
			data : count,
			type : "POST",
			success:function(res){
				if(!isNaN(res.area)) {
					return;
				}
				$(".page").show();
				if(parent==0) {
					page(res);// 调用html渲染方法
				} else {
					getdataSon(res);// 调用html渲染方法
				}
			}
		})
		return false;   // 阻止a标签跳转
	});

	$('.sorting').click(function(){
		var parent = $(".area-parent").attr("data-id");
		var sort = $(this).attr('data-name');
		var asc = $(this).attr('data-asc');
		if(asc == "asc"){
			$(this).attr("data-asc","desc");
		} else {
			$('.sorting').attr("data-asc","desc");
			$(this).attr("data-asc","asc");
		}
		var form = $("#form").serialize()+'&'+$("#count").serialize()+'&sort='+sort+'&asc='+asc+'&parent='+parent;
		$.ajax({
			type:"POST",
			url :"/admin/area/area",
			data:form,
			success:function(data){
				if(!isNaN(data.area)) {
					$("#no-area").parent().remove();
					$(".list").children('tr').remove();
					$(".page").remove();
					if(parent==0) {
						tr = '<input type="hidden" class="area-parent" data-id="'+data.area+'"><tr><td colspan="15" id="no-area" style="color:red;border-bottom: none;">暂无相关的记录显示</td></tr>';
					} else {
						$("#data-tr").parent().remove();
						tr = '<input type="hidden" class="area-parent" data-id="'+data.area+'"><tr><td id="data-tr" colspan="15" style="color:red;border-bottom: none;">暂无相关的记录显示<br/><a href="javascript:void(0)" style="margin-left:10px" onclick="getUp(this)" data-id='+data.area+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一级" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px;margin-left:-10px;border-bottom: none;"></a></td></tr>';
					}
					$('.list').html(tr);
					return;
				}
				$(".page").show();
				if(parent==0) {
					page(data);// 调用html渲染方法
				} else {
					getdataSon(data);// 调用html渲染方法
				}
			}
		})
	});
})
//搜索
$(function(){
	// 搜索点击事件
	$("#sub-btn").click(function(e) {
		e.preventDefault();//阻止form表单提交
		$("#data-tr").parent().remove();
		$('[data-name]').attr('class','sorting');
		$('[data-name]').attr('data-asc','desc');
		var parent = $(".area-parent").attr("data-id");
	    var form = $("#form").serialize()+'&'+$("#count").serialize()+'&parent='+parent+'&sort=a.id &asc=asc';
		$.ajax({
			url : "/admin/area/area",
			data : form,
			type : "POST",
			success:function(res){
				$(".page").show();
				if(!isNaN(res.area)) {
					$("#no-area").parent().remove();
					$(".list").children('tr').remove();
					$(".page").hide();
					if(parent==0) {
						tr = '<input type="hidden" class="area-parent" data-id="'+res.area+'"><tr><td colspan="15" id="no-area" style="color:red;border-bottom: none;">暂无相关的记录显示</td></tr>';
					} else {
						tr = '<input type="hidden" class="area-parent" data-id="'+res.area+'"><tr><td id="data-tr" colspan="15" style="color:red;border-bottom: none;">暂无相关的记录显示<br/><a href="javascript:void(0)" style="margin-left:10px" onclick="getUp(this)" data-id='+res.area+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一级" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px;margin-left:-10px;border-bottom: none;"></a></td></tr>';
					}
					$('.list').html(tr);
					return;
				}
				if(res.area[0].parent==0) {
					page(res); // 调用html渲染方法
				} else {
					getdataSon(res);
				}
			}
		})
		return false;   // 阻止a标签跳转

	});
})

$(function(){
	// 点击分页事件
	$('.page').delegate('a','click',function(){
		var url = $(this).attr('href'); // url
		var parent = $(".area-parent").attr("data-id");
		var form = $("#form").serialize()+'&'+$("#count").serialize()+'&parent='+parent+'&sort=a.id &asc=asc';
		$.ajax({
			url:url,
			data:form,
			success:function(res){
				$(".page").show();
				if(res.area[0].parent==0){
					page(res); // 调用html渲染方法
				} else {
					getdataSon(res);
				}
			}
		})
		return false;  // 阻止a标签跳转
	});
})
//渲染第一级
function page(res){
	$('[name="checkme"] > input').prop("checked",false);
	tr = ''; // 定义一个容器
	$('.page').html(res.page); // 渲染替换之前分页按钮
	delete res.page; // 删除之前返回的分页按钮
	if(!isNaN(res.area)) {
		$("#no-area").parent().remove();
		tr = '<tr><td colspan="15" id="no-area" style="color:red;border-bottom: none;">暂无相关的记录显示</td></tr>';
		$('.list').html(tr);
		return;
	} else {
		$("#no-area").parent().remove();
	}
	if(!res.order) {
		for(var k in res.area){
			var sum = parseInt(k) + parseInt(1); // 行号
			if(res.area[k].is_lock == 1){
					var isLock = '<span style="color: red">N</span>';
				}else{
					var isLock = 'Y';
			}
			if(res.area[k].is_hidden == 1){
					var isHidden = 'Y';
				}else{
					var isHidden = '<span style="color: red">N</span>';
			}
			if(res.area[k].is_country == 1){
					var isCountry = 'Y';
				}else{
					var isCountry = '<span style="color: red">N</span>';
			}

		// 要渲染的内容数据
			tr+='<input type="hidden" class="area-parent" data-id="'+res.area[k].parent+'""><tr><td><input onclick="getData()" type="checkbox" name="ids[]" value="'+res.area[k].data_id+'"></td><td name="xg" class="jsgrid-cell jsgrid-control-field jsgrid-align-center" style="text-align: center;"><a href="/admin/area/areaShow?id='+res.area[k].data_id+'"class="text-inverse  p-r-10" title="" data-toggle="tooltip" data-original-title="Edit"><i class="fa fa-pencil"></i></a></td><td name="sc"><a href="/admin/area/isDeleteArea?id='+res.area[k].data_id+'" class="text-inverse" title="" data-toggle="tooltip" data-original-title="Delete"><i class="fa fa fa-trash"></i></a></td><td name="checkme"><a href="javascript:void(0)" onclick="getNext(this)" data-id='+res.area[k].data_id+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="管理下一级" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;"></a></td><td name="hh">'+sum+'</td><td name="bh">'+res.area[k].data_id+'</td><td name="mc">'+res.area[k].name+'</td><td name="ywmc">'+res.area[k].en_name+'</td><td name="pxh">'+res.area[k].sort+'</td><td name="gj">'+isCountry+'</td><td name="sd">'+isLock+'</td><td name="xs">'+isHidden+'</td><td name="py">'+res.area[k].pinyin+'</td><td name="pyjx">'+(res.area[k].spinyin==null?"":res.area[k].spinyin)+'</td><td name="bzsm"><div style="max-height:30px;width:100%;overflow: hidden;text-overflow: ellipsis;font-size:12px">'+(res.area[k].remark==null?"":res.area[k].remark)+'</div></td></tr>';

		}
	} else {
		for(var k in res.area){
			var sum = parseInt(k) + parseInt(1); // 行号
			if(res.area[k].is_lock == 1){
					var isLock = '<span style="color: red">N</span>';
				}else{
					var isLock = 'Y';
			}
			if(res.area[k].is_hidden == 1){
					var isHidden = 'Y';
				}else{
					var isHidden = '<span style="color: red">N</span>';
			}
			if(res.area[k].is_country == 1){
					var isCountry = 'Y';
				}else{
					var isCountry = '<span style="color: red">N</span>';
			}

			// delete res.area.order;
		// 要渲染的内容数据
			tr+='<input type="hidden" class="area-parent" data-id="'+res.area[k].parent+'""><tr><td><input type="checkbox" onclick="getData()" name="ids[]" value="'+res.area[k].data_id+'"></td><td name="xg" class="jsgrid-cell jsgrid-control-field jsgrid-align-center" style="text-align: center;"><a href="/admin/area/areaShow?id='+res.area[k].data_id+'"class="text-inverse  p-r-10" title="" data-toggle="tooltip" data-original-title="Edit"><i class="fa fa-pencil"></i></a></td><td name="sc"><a href="/admin/area/isDeleteArea?id='+res.area[k].data_id+'" class="text-inverse" title="" data-toggle="tooltip" data-original-title="Delete"><i class="fa fa fa-trash"></i></a></td><td name="checkme"><a href="javascript:void(0)" onclick="getNext(this)" data-id='+res.area[k].data_id+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="管理下一级" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;"></a></td>';

			for(var i in res.order){ // 遍历列表排序
				switch(i){
					case 'hh':
			    		var hh = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="hh"'+hh+' >'+sum+'</td>';
			    	break;
			    	case 'bh':
			    		var bh = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="bh"'+bh+' >'+res.area[k].data_id+'</td>';
			    	break;
			    	case 'mc':
			    		var mc = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="mc"'+mc+' >'+res.area[k].name+'</td>';
			    	break;
			    	case 'ywmc':
			    		var ywmc = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="ywmc"'+ywmc+' >'+res.area[k].en_name+'</td>';
			    	break;
			    	case 'pxh':
			    		var pxh = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="pxh"'+pxh+' >'+res.area[k].sort+'</td>';
			    	break;
			    	case 'gj':
			    		var gj = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="gj"'+gj+' >'+isCountry+'</td>';
			    	break;
			    	case 'sd':
			    		var sd = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="sd"'+sd+' >'+isLock+'</td>';
			    	break;
			    	case 'xs':
			    		var xs = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="xs"'+xs+' >'+isHidden+'</td>';
			    	break;
			    	case 'py':
			    		var py = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="py"'+py+' >'+res.area[k].pinyin+'</td>';
			    	break;
			    	case 'pyjx':
			    		var pyjx = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="pyjx"'+pyjx+' >'+(res.area[k].spinyin==null?"":res.area[k].spinyin)+'</td>';
			    	break;
			    	case 'bzsm':
			    		var pyjx = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="pyjx"'+pyjx+' ><div style="max-height:30px;width:100%;overflow: hidden;text-overflow: ellipsis;font-size:12px">'+(res.area[k].remark==null?"":res.area[k].remark)+'</div></td>';
			    	break;
				}
			}

			tr+='</tr>';
		}
	}
	// 渲染内容
	$('.list').html(tr);
}
//渲染管理下一级和返回上一级
function getdataSon(res){
	$('[name="checkme"] > input').prop("checked",false);
	tr = ''; // 定义一个容器
	$('.page').html(res.page); // 渲染替换之前分页按钮
	delete res.page; // 删除之前返回的分页按钮
	if(!isNaN(res.area)) {
		$("#no-area").parent().remove();
		tr = '<tr><td colspan="15" id="no-area" style="color:red;border-bottom: none;">暂无相关的记录显示</td></tr>';
		$('.list').html(tr);
		return;
	} else {
		$("#no-area").parent().remove();
	}
	if(!res.order) {
		for(var k in res.area){
			var sum = parseInt(k) + parseInt(1); // 行号
			if(res.area[k].is_lock == 1){
					var isLock = 'N';
				}else{
					var isLock = 'Y';
			}
			if(res.area[k].is_hidden == 1){
					var isHidden = 'Y';
				}else{
					var isHidden = 'N';
			}
			if(res.area[k].is_country == 1){
					var isCountry = 'Y';
				}else{
					var isCountry = 'N';
			}

		// 要渲染的内容数据
			tr+='<input type="hidden" class="area-parent" data-id="'+res.area[k].parent+'""><tr><td><input type="checkbox" onclick="getData()" name="ids[]" value="'+res.area[k].data_id+'"></td><td name="xg" class="jsgrid-cell jsgrid-control-field jsgrid-align-center" style="text-align: center;"><a href="/admin/area/areaShow?id='+res.area[k].data_id+'"class="text-inverse  p-r-10" title="" data-toggle="tooltip" data-original-title="Edit"><i class="fa fa-pencil"></i></a></td><td name="sc"><a href="./isDeleteArea?id='+res.area[k].data_id+'" class="text-inverse" title="" data-toggle="tooltip" data-original-title="Delete"><i class="fa fa fa-trash"></i></a></td><td name="checkme"><a href="javascript:void(0)" onclick="getNext(this)" data-id='+res.area[k].data_id+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="管理下一级" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;"></a><br/><a href="javascript:void(0)" onclick="getUp(this)" data-id='+res.area[k].parent+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一級" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px"></a></td><td name="hh">'+sum+'</td><td name="bh">'+res.area[k].data_id+'</td><td name="mc">'+res.area[k].name+'</td><td name="ywmc">'+res.area[k].en_name+'</td><td name="pxh">'+res.area[k].sort+'</td><td name="gj">'+isCountry+'</td><td name="sd">'+isLock+'</td><td name="xs">'+isHidden+'</td><td name="py">'+res.area[k].pinyin+'</td><td name="pyjx">'+(res.area[k].spinyin==null?"":res.area[k].spinyin)+'</td><td name="bzsm"><div style="max-height:30px;width:100%;overflow: hidden;text-overflow: ellipsis;font-size:12px">'+(res.area[k].remark==null?"":res.area[k].remark)+'</div></td></tr>';
		}
	} else {
		for(var k in res.area){
			var sum = parseInt(k) + parseInt(1); // 行号
			if(res.area[k].is_lock == 1){
					var isLock = 'N';
				}else{
					var isLock = 'Y';
			}
			if(res.area[k].is_hidden == 1){
					var isHidden = 'Y';
				}else{
					var isHidden = 'N';
			}
			if(res.area[k].is_country == 1){
					var isCountry = 'Y';
				}else{
					var isCountry = 'N';
			}

			// delete res.area.order;
		// 要渲染的内容数据
			tr+='<input type="hidden" class="area-parent" data-id="'+res.area[k].parent+'""><tr><td><input type="checkbox" onclick="getData()" name="ids[]" value="'+res.area[k].data_id+'"></td><td name="xg" class="jsgrid-cell jsgrid-control-field jsgrid-align-center" style="text-align: center;"><a href="/admin/area/areaShow?id='+res.area[k].data_id+'"class="text-inverse  p-r-10" title="" data-toggle="tooltip" data-original-title="Edit"><i class="fa fa-pencil"></i></a></td><td name="sc"><a href="/admin/area/isDeleteArea?id='+res.area[k].data_id+'" class="text-inverse" title="" data-toggle="tooltip" data-original-title="Delete"><i class="fa fa fa-trash"></i></a></td><td name="checkme"><a href="javascript:void(0)" onclick="getNext(this)" data-id='+res.area[k].data_id+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="管理下一级" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;"></a><br/><a href="javascript:void(0)" onclick="getUp(this)" data-id='+res.area[k].parent+'><input type="button" name="btnAdd" data-toggle="modal" data-target="#editor-modal" value="返回上一級" id="btnAdd" class="SrvButton" style="padding: 3px 20px;background-color: #566FC9;color: #fff;border: 1px solid #566FC9;outline: none;margin-top:5px"></a></td>';

			for(var i in res.order){ // 遍历列表排序
				switch(i){
					case 'hh':
			    		var hh = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="hh"'+hh+' >'+sum+'</td>';
			    	break;
			    	case 'bh':
			    		var bh = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="bh"'+bh+' >'+res.area[k].data_id+'</td>';
			    	break;
			    	case 'mc':
			    		var mc = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="mc"'+mc+' >'+res.area[k].name+'</td>';
			    	break;
			    	case 'ywmc':
			    		var ywmc = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="ywmc"'+ywmc+' >'+res.area[k].en_name+'</td>';
			    	break;
			    	case 'pxh':
			    		var pxh = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="pxh"'+pxh+' >'+res.area[k].sort+'</td>';
			    	break;
			    	case 'gj':
			    		var gj = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="gj"'+gj+' >'+isCountry+'</td>';
			    	break;
			    	case 'sd':
			    		var sd = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="sd"'+sd+' >'+isLock+'</td>';
			    	break;
			    	case 'xs':
			    		var xs = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="xs"'+xs+' >'+isHidden+'</td>';
			    	break;
			    	case 'py':
			    		var py = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="py"'+py+' >'+res.area[k].pinyin+'</td>';
			    	break;
			    	case 'pyjx':
			    		var pyjx = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="pyjx"'+pyjx+' >'+(res.area[k].spinyin==null?"":res.area[k].spinyin)+'</td>';
			    	break;
			    	case 'bzsm':
			    		var pyjx = res.order[i][1] == 0 ? 'data="hide"; style="display: none;"' : '';
			    		tr+='<td name="pyjx"'+pyjx+' ><div style="max-height:30px;width:100%;overflow: hidden;text-overflow: ellipsis;font-size:12px">'+(res.area[k].remark==null?"":res.area[k].remark)+'</div></td>';
			    	break;
				}
			}

			tr+='</tr>';
		}
	}

	// 渲染内容
	$('.list').html(tr);
}

//新增
$(function(){
	$("#area-insert").click(function(){
		var parent = $(".area-parent").attr("data-id");
		window.location.href = "/admin/area/areaShow?parent="+parent;
	})
})
//批量删除
$(function(){
	$("#Deletes").click(function(){
		var ids = $("input[name='ids[]']:checked").serialize();
		if(ids) {
			var parent = $(".area-parent").attr("data-id");
			$.ajax({
				type:"POST",
				url :"/admin/area/isDeleteAllArea",
				data:ids,
				success:function(data){
					if(data.code==1) {
						window.location = "/admin/area/area?parent="+parent;
					}
				}
			})
		}
		return false;
	})
})

function getReload(){
	var parent = $(".area-parent").attr("data-id") ;
	var page = $(".active").children("span").text();
	window.location.href = "/admin/area/area?parent="+parent+"&page="+page;
}
</script>